﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace Zombie_Demo.World.NPC
{
     public class NPC : AI
     {
          protected string sprite;
          protected bool animated;
          protected Rectangle box; //TODO: Implement animation
          protected Vector2 spriteOrigin;
          protected Utilities.Animation anim;

          public Texture2D Sprite { get { return Utilities.ContentLibrary.GetTexture(sprite); } }
          override public Vector2 Position { get { return this.position; } }
          override public float Rotation { get { return this.rotation; } }

          public NPC() : base()
          {
               sprite = "Zombie_Sheet";
               position = Vector2.Zero;
               rotation = 0.0f;
          }

          public NPC(string sprite, Vector2 position)
          {
               this.sprite = sprite;
               this.position = position;
          }

          /// <summary>
          /// Will be depreciated, testing function.
          /// </summary>
          /// <param name="position">Position of the npc</param>
          public NPC(Vector2 position) : base()
          {
               this.sprite = "Zombie_Sheet";
               this.position = position;
               rotation = 0.0f;
               this.box = new Rectangle(0, 0, 48, 48);
               animated = true;
          }

          public NPC(Vector2 position, Vector2 anchor, bool wander, int leash, string sprite)
               : base(anchor, wander, leash)
          {
               this.position = position;
               this.sprite = sprite;
               this.box = new Rectangle(0, 0, 48, 48);
               animated = true;
               spriteOrigin = new Vector2(box.Width / 2, box.Height / 2);
               anim = new Utilities.Animation(sprite, 1, 1, 8, 1, 8, 1, 1, 0);
          }

          public new void Update(GameTime gameTime)
          {
               base.Update(gameTime);

               

               if (this.CurrentStep == StepType.Rest)
                    this.anim.Paused = true;
               else
                    this.anim.Paused = false;
          }

          public void Draw(GameTime gameTime, SpriteBatch spriteBatch)
          {
               if (animated)
               {
                    //if (this.heading == 1)
                    //{
                         spriteBatch.Draw(Utilities.ContentLibrary.GetTexture(sprite),
                              new Vector2((int)position.X, (int)position.Y),
                              anim.GetImage(gameTime),
                              Color.White,
                              this.SpriteRot,
                              spriteOrigin,
                              1,
                              SpriteEffects.None,
                              0);
                    //}
                    //else
                    //{
                    //     spriteBatch.Draw(Utilities.ZDContentManager.GetTexture(sprite),
                    //          new Vector2((int)position.X, (int)position.Y),
                    //          anim.GetImage(gameTime),
                    //          Color.White,
                    //          this.Rotation,
                    //          spriteOrigin,
                    //          1,
                    //          SpriteEffects.FlipHorizontally,
                    //          0);
                    //}
               }
               else
                    spriteBatch.Draw(Utilities.ContentLibrary.GetTexture(sprite), position, null, Color.White, this.Rotation, spriteOrigin, 1, SpriteEffects.None, 0);
          }
     }
}
